package oas.config;

import javax.sql.DataSource;

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

/**
 * 数据库配置
 *
 * @author liyue
 * @version v1.0.0
 */
@Configuration
public class DataConfig {

	/**
	 * 使用基于JDBC驱动的数据源，采用MySQL数据库
	 *
	 * @return
	 */
	@Bean
	public BasicDataSource dataSource() {
		BasicDataSource bds = new BasicDataSource();
		bds.setDriverClassName("com.mysql.cj.jdbc.Driver");
		bds.setUrl("jdbc:mysql://8.131.60.81:3306/oas?&useSSL=false&serverTimezone=Asia/Shanghai");
		bds.setUsername("root");
		bds.setPassword("SpringT9");
		bds.setInitialSize(5);
		bds.setMaxTotal(10);
		return bds;
	}

	/**
	 * jdbc模板配置，采用spring默认的JdbcTemplate模板
	 *
	 * @param dataSource
	 *            数据源
	 * @return
	 */
	@Bean
	public JdbcTemplate jdbcTemplate(DataSource dataSource) {
		return new JdbcTemplate(dataSource);
	}

}